package com.shy.example.service.consumer.controller;

import com.shy.example.service.consumer.service.ProviderFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("echo")
@Slf4j
public class EchoController {
    private static String SERVICE_PROVIDER = "http://service-provider";
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private ProviderFeignService providerFeignService;

    @GetMapping("name")
    public String name(String name){
        log.info("service consumer method name");
        return "hello, name is " + name;
    }

    @GetMapping("ribbon")
    public String ribbon(String name){
        return restTemplate.getForObject(SERVICE_PROVIDER + "/echo/name?name=" + name, String.class);
    }

    @GetMapping("feign")
    public String feign(String name){
        return providerFeignService.name(name);
    }

    @GetMapping("timeout")
    public String timeout(){
        return providerFeignService.timeout();
    }
}
